package cn.tedu.elo.pet_breeds.service.impl;

import cn.tedu.elo.pet_breeds.mapper.Pet_breedsMapper;
import cn.tedu.elo.pet_breeds.pojo.dto.Pet_breedsQuery;
import cn.tedu.elo.pet_breeds.pojo.dto.Pet_breedsSaveParam;
import cn.tedu.elo.pet_breeds.pojo.entity.Pet_breeds;
import cn.tedu.elo.pet_breeds.pojo.vo.Pet_breedsVO;
import cn.tedu.elo.pet_breeds.service.Pet_breedsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class Pet_breedsServiceImpl implements Pet_breedsService {
    @Autowired
    Pet_breedsMapper pet_breedsMapper;

    @Override
    public List<Pet_breedsVO> selectPet_breeds(Pet_breedsQuery pet_breedsQuery) {
        log.debug("查询宠物品种业务:pet_breedsQuery={}", pet_breedsQuery);
        List<Pet_breedsVO> list = pet_breedsMapper.selectPet_breeds(pet_breedsQuery);
        return list;
    }
    @Override
    public void savePet(Pet_breedsSaveParam petSaveParam) {
        log.debug("保存宠物业务，参数：{}", petSaveParam);
        Pet_breeds pet = new Pet_breeds();
        BeanUtils.copyProperties(petSaveParam, pet);
        if (pet.getId() == null) {//新增
            pet.setCreateTime(new Date());
            log.debug("用户对象：{}", pet);
            pet_breedsMapper.insert(pet);
        } else {//更新
            pet.setUpdateTime(new Date());
            pet_breedsMapper.update(pet);
        }
    }
    @Override
    public void deletePet_breeds(Long id) {
        log.debug("删除宠物品种业务:id={}", id);
        pet_breedsMapper.deletePet_breeds(id);
    }


}
